package com.hzncc.flowable_diboot.controller;

import com.diboot.core.vo.JsonResult;
import com.diboot.core.vo.LabelValue;
import com.hzncc.flowable_diboot.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private IReportService reportService;

    @GetMapping("/briefing/{type}")
    public JsonResult<?> salesBriefing(@PathVariable String type) {
        return JsonResult.OK(reportService.getSalesBriefing(type));
    }

    @GetMapping("/achievement/{type}")
    public JsonResult<?> achievement(@PathVariable String type) {
        return JsonResult.OK(reportService.getAchievement(type));
    }

    //@GetMapping("/dailyReport")
    //public JsonResult<?> dailyReport(LocalDate begin, LocalDate end,String name){
    //    return JsonResult.OK(reportService.dailyReport(begin,end,name));
    //}

    /**
     * 销售趋势
     */
    @GetMapping("/salesTrends/{type}")
    public JsonResult<?> salesTrends(@PathVariable String type) {
        return JsonResult.OK(reportService.salesTrends(type));
    }

    /**
     * 销售漏斗
     */
    @GetMapping("/salesFunnels/{type}")
    public JsonResult<?> salesFunnels(@PathVariable String type) {
        return JsonResult.OK(reportService.salesFunnels(type));
    }


    /**
     * 获取年份下拉选项
     * @return
     * @throws Exception
     */
    @GetMapping("/years")
    public JsonResult<?> getYears() throws Exception {
        List<LabelValue> list = new ArrayList<>();
        int start = 2023;
        int year = LocalDate.now().getYear();
        for (int i = 0; i <= year - start; i++) {
            list.add(new LabelValue(String.valueOf(start + i), String.valueOf(start + i)));
        }
        return JsonResult.OK(list);
    }
}
